/*
*	(*^。^*) TFrameWork License (*^。^*)
*/

/*
 *  Title :  
 *          
 *  Description :  
 *          
 *          
 *  Date : 
 *
 *  Author : DengPing
 *
 *  Modify : 
 */
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;

namespace TFrameWork.Module.ActionEditor
{
    internal partial class ActionEditor
    {
        private Texture2D recordOffImg;
        private Texture2D recordOnImg;

        private Button PreviouFrameButton;
        private Button PlayButton;
        private Button NextFrameButton;
        private Button FirstFrameButton;
        private Button LastFameButton;
        private Button TranscribeButton;

        private void InitConsole()
        {
            PreviouFrameButton = _root.Q<Button>(nameof(PreviouFrameButton));
            var preKey = EditorGUIUtility.IconContent("d_Animation.PrevKey@2x");
            PreviouFrameButton.style.backgroundImage = new StyleBackground(preKey.image as Texture2D);
            PreviouFrameButton.clicked += PreviouFrameButtonClick;
            
            PlayButton = _root.Q<Button>(nameof(PlayButton));
            var playImg = EditorGUIUtility.IconContent("d_PlayButton On@2x");
            PlayButton.style.backgroundImage = new StyleBackground(playImg.image as Texture2D);
            PlayButton.clicked += PlayButtonClick;

            
            NextFrameButton = _root.Q<Button>(nameof(NextFrameButton));
            var nextKey = EditorGUIUtility.IconContent("d_Animation.NextKey@2x");
            NextFrameButton.style.backgroundImage = new StyleBackground(nextKey.image as Texture2D);
            NextFrameButton.clicked += NextFrameButtonClick;

            FirstFrameButton = _root.Q<Button>(nameof(FirstFrameButton));
            var firstKey = EditorGUIUtility.IconContent("d_Animation.FirstKey@2x");
            FirstFrameButton.style.backgroundImage = new StyleBackground(firstKey.image as Texture2D);
            FirstFrameButton.clicked += FirstFrameButtonClick;
                
            LastFameButton = _root.Q<Button>(nameof(LastFameButton));
            var lastKey = EditorGUIUtility.IconContent("d_Animation.LastKey@2x");
            LastFameButton.style.backgroundImage = new StyleBackground(lastKey.image as Texture2D);
            LastFameButton.clicked += LastFameButtonClick;

            TranscribeButton = _root.Q<Button>(nameof(TranscribeButton));
            TranscribeButton.clicked += TranscribeButtonClick;
        }

        private void DisablePlayButtons()
        {
            DisableElement(PreviouFrameButton);
            DisableElement(PlayButton);
            DisableElement(NextFrameButton);
            DisableElement(FirstFrameButton);
            DisableElement(LastFameButton);
        }

        private void EnablePlayButtons()
        {
            EnableElement(PreviouFrameButton);
            EnableElement(PlayButton);
            EnableElement(NextFrameButton);
            EnableElement(FirstFrameButton);
            EnableElement(LastFameButton);
        }
        
        private void EnableElement(VisualElement element)
        {
            element.SetEnabled(true);
            element.pickingMode = PickingMode.Position;
        }

        private void DisableElement(VisualElement element)
        {
            element.SetEnabled(false);
            element.pickingMode = PickingMode.Ignore;
        }
        
        private void TranscribeButtonClick()
        {
            IsRecordEvent = !IsRecordEvent;
        }

        private void FirstFrameButtonClick()
        {
            IsPlaying = false;
            CurrentSelectFrameIndex = 0;
            mainContentView.horizontalScroller.value = 0;
        }

        private void LastFameButtonClick()
        {
            IsPlaying = false;
            CurrentSelectFrameIndex = CurrentFrameCount;
            mainContentView.horizontalScroller.value = contentListView.style.width.value.value;
        }

        private void PreviouFrameButtonClick()
        {
            IsPlaying = false;
            CurrentSelectFrameIndex -= 1;
        }

        private void PlayButtonClick()
        {
            IsPlaying = !IsPlaying;
        }

        private void NextFrameButtonClick()
        {
            IsPlaying = false;
            CurrentSelectFrameIndex += 1;
        }
        
    }
}
